#ifndef PIECE_H_
#define PIECE_H_

#include "../Game/Enums.h"

#include <string>
#include <vector>
#include <map>
using namespace std;

namespace Core
{
	// forward declarations
	class Chessboard;
	class Player;
	class Move;
	class MoveTracker;
	class Square;
	
	/*
	 * abstract base class for pieces 
	 */
	class Piece
	{
	public:
		Piece(Player * player, Square * square = NULL);
		~Piece();

		virtual std::string name() const = 0;
		virtual ChType type() const = 0;

		ChColor color() const;
		int key() const;
		Player * player() const;
		Square * square() const;
		void square(Square * val);
		bool isEaten() const;
		void setEaten(bool val);
		
		bool checkDestination(Move * mv) const;
		bool hasNotMovedYet() const;
		const Move * canMove(Square * dst);
		void move(const Move& mv);
		void undoMove();
		void redoMove();
		void deleteValidMoves();
		map<int, Move*> & validMoves();

	protected:
		MoveTracker * tracker() const { return _tracker; }

		virtual void updateValidMoves() = 0;
		map<int, Move*> _validMoves;
		bool validMovesExpired() const;
		void validMovesUpdated();

	private:
		Player * _plr;
		Square * _sq;
		bool _isEaten;
		int _validMovesUpdateCount;
		MoveTracker * _tracker;
	};
}

#endif
